package cn.sfa.controller.redlist;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sfa.common.pagination.Pagination;
import cn.sfa.common.utils.WebInitBinderContoller;
import cn.sfa.entity.affixItem.SaleAffixItem;
import cn.sfa.entity.users.SaleUsersLogin;
import cn.sfa.service.affix.AffixService;
import cn.sfa.service.agentinfo.AgentInfoService;
import cn.sfa.service.promote.PromoteSerice;

@Controller
@RequestMapping("/news/redlist/index")
public class RedListController extends WebInitBinderContoller {

	Logger log = LoggerFactory.getLogger(RedListController.class);
	
	@Autowired
	PromoteSerice promoteSerice;
	@Autowired
	private AffixService affixService;
	@Autowired
	private AgentInfoService agentInfoService;

	@RequestMapping("/list")
	public String index(HttpServletRequest request, ModelMap map) {
		
		SaleUsersLogin user = (SaleUsersLogin) request.getSession()
		.getAttribute("user");
		
		//代理人荣誉
		Pagination paginationpromote  = agentInfoService.seachPromotPre(1, 10, "", user.getBranchId());
		
		// 荣誉殿堂
		List affix=paginationpromote.getResultList();
		for(int i=0;i<affix.size();i++)
		{
			Map<String,Object> m=(Map<String,Object>)affix.get(i);
			if(m.get("affixMainId")!=null)
			{
				m.put("path", "/images/imageCut/man.GIF");
				List<SaleAffixItem> affixs=affixService.getAffix("USERPHOTO", (String)m.get("affixMainId"));
				for(SaleAffixItem a:affixs)
				{
					if(a.getIsTrue()!=null && a.getIsTrue().equals("Y"))
					{
						String path=a.getSALEAFFIXITEMFILEPATH();
						m.put("path", path);
					}else
					{
						m.put("path", "/images/imageCut/man.GIF");
					}
				}
				
			}
		}
		
		map.put("paginationpromote", paginationpromote);
		return "redlist/list";
	}
}
